<?php
namespace Home\Controller;
use Think\Controller;
// 开发者：杨晓杰，
// 邮箱：2902468225@qq.com 


// 企业控制器，负责企业相关操作
class CpnController extends Controller {
	private $dbName='campany';
	// 企业列表
	public function listPage(){
		tag('func');
		$key=I('get.key');
		$area=I('get.area');
		$indus=I('get.indus');
		// 根据公司名、规模、发展阶段、行业、地区查找公司
		$where['is_verify']=1;
        $where['is_black']=0;
		if($key)$where['name|scale|stage|industry|area']=array('like',"%".$key."%");
		if($area)$where['area']=array('like',"%".$area."%");
		if($indus)$where['industry']=array('like',"%".$indus."%");
		$all=M($this->dbName)->where($where)->order('parise desc')->select();
		$data=R('Myfunc/Myfunc/pageDeal',array('data'=>$all));

		//添加是否点赞过
        $length=count($data['list']);
        $where2['ip']=get_client_ip();
        $where2['aim_type']=2;
        for($i=0;$i<$length;$i++){
            $where2['aim_id']=$data['list'][$i]['id'];
            if(M('parise')->where($where2)->find())$data['list'][$i]['is_parise']=1;
            else $data['list'][$i]['is_parise']=0;
        }

		$data['key']=$key;
		$data['area']=$area;
		$data['indus']=$indus;
		$data['areaList']=array(0=>'广州',1=>'深圳',2=>'北京',3=>'上海',4=>'杭州');
		$data['indusList']=array(0=>'房地产',1=>'互联网',2=>'金融',3=>'广告',4=>'制造业');
		if(I('get.json')==1){
			echo json_encode($data);
			return;
		}
		$this->assign('data',$data);
		// dump($data);
        R('Page/camList');
	}
	// 企业详情
	public function detail(){
		tag('func');
		$id=I('get.id')?I('get.id'):1;
        $data['company']=M($this->dbName)->where('id ='.$id.' and is_black = 0')->find();
        // 学生用户是否like过
        if($_ENV['user']['type']==1){
            if(M('like')->where('like_type = 0 and cam_id = '.$id.' and std_id = '.$_ENV['user']['id'].' and like_status != 2')->find())$data['is_like']=1;
            else $data['is_like']=0;
        }
        // 今天是否点过赞
        $data['is_parise']=R('Myfunc/Myfunc/isParise',array('aim_id'=>$id,'aim_type'=>2));
        $data['comment']=R('Myfunc/Comment/commentList',array('cpn_id'=>$id,'is_verify'=>1));

        //企业最新资讯
        $data['news']=M('news')->where('cam_id = '.$id)->order('id desc')->limit(6)->select();

        //企业职位需求
        $data['work']=M('work')->where('cam_id = '.$id.' and is_show = 1')->order('work_id desc')->limit(3)->select();
        
        //企业产品
        $data['production']=M('production')->where('cam_id = '.$id)->select();

       	// 企业成员
       	$data['member']=M('member')->where('cam_id = '.$id)->limit(4)->select();
       	
        $this->assign('data',$data);
		// dump($data);
        R('Page/camDetail');
	}
	// 相关企业
    public function relev(){
        if(I('get.industry'))$where['industry']=array('like','%'.I('get.industry').'%');
        $where['is_black']=0;
        $all=M($this->dbName)->where($where)->order('parise desc')->select();
        $data=R('Myfunc/Myfunc/pageDeal',array('data'=>$all));
        echo json_encode($data);
    }
}